// by Pumpkin

#define __awc(wtype,wcount) _vec addWeaponCargo [wtype,wcount];
#define __amc(mtype,mcount) _vec addMagazineCargo [mtype,mcount];

private ["_vec","_wpnarray","_type","_name","_amount"];

_vec = _this select 0;
_side = d_own_side;
if (count _this > 1) then {_side = _this select 1};
If (isNil "_side") then {_side = d_own_side; };

if (_side == d_own_side) then {
	_wpnarray = ["d_weapon_array_player",[]] call XNetGetJIP;
} else {
	_wpnarray = ["d_weapon_array_enemy",[]] call XNetGetJIP;
};

if (d_global_debug > 0) then { diag_log Format["(%1)[%2]: %3: %4  Input:%5 (%6)",diag_tickTime,"weaponcargo2.sqf","Starting to fill",_vec, _this, count(_wpnarray)];};
clearMagazineCargo _vec;
clearWeaponCargo _vec;

{
	_type = _x select 0;
	_name = _x select 1;
	_amount = _x select 2;
	If (_type == 1) then {
		__awc(_name,_amount)
	} else {
		__amc(_name,_amount)
	};
	//diag_log Format["Filled box with %1 (%2) %3",_name, _amount, _type];
} foreach _wpnarray;
if (d_global_debug > 0) then { diag_log Format["(%1)[%2]: %3 (%4)",diag_tickTime,"weaponcargo2.sqf","Ammo Box filled!",_vec];};
